//////
//////  Swizzling.swift
//////  JoTravel
//////
//////  Created by tong on 15/11/30.
//////  Copyright © 2015年 zhuxietong. All rights reserved.
//////
////
////import Foundation
////import UIKit
////
////
////extension UIViewController {
////    public override class func initialize() {
////        struct Static {
////            static var token: dispatch_once_t = 0
////        }
////
////        // make sure this isn't a subclass
////        if self !== UIViewController.self {
////            return
////        }
////
////        dispatch_once(&Static.token) {
////            let originalSelector = Selector("viewDidLoad")
////            let swizzledSelector = Selector("jo_viewDidLoad")
////
////            let originalMethod = class_getInstanceMethod(self, originalSelector)
////            let swizzledMethod = class_getInstanceMethod(self, swizzledSelector)
////
////            let didAddMethod = class_addMethod(self, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))
////            if didAddMethod {
////                class_replaceMethod(self, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod))
////            } else {
////                method_exchangeImplementations(originalMethod, swizzledMethod);
////            }
////        }
////        dispatch_once(&Static.token) {
////            let originalSelector = Selector("viewWillAppear")
////            let swizzledSelector = Selector("jo_viewWillAppear")
////
////            let originalMethod = class_getInstanceMethod(self, originalSelector)
////            let swizzledMethod = class_getInstanceMethod(self, swizzledSelector)
////
////            let didAddMethod = class_addMethod(self, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))
////            if didAddMethod {
////                class_replaceMethod(self, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod))
////            } else {
////                method_exchangeImplementations(originalMethod, swizzledMethod);
////            }
////        }
////
////    }
////
////    // MARK: - Method Swizzling
////    func jo_viewDidLoad() {
////        self.controller_style = ControllerStyle.White_Black_tyle()
////        self.jo_viewDidLoad()
////        self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "返回", style: .plain, target: nil, action: nil)
////    }
////
////    func jo_viewWillAppear() {
////        self.jo_viewWillAppear()
////
////        if let style = self.controller_style
////        {
////            if let nav = self.navigationController
////            {
////                nav.nav_ctr_style = style
////            }
////        }
////    }
////
////}
//
////
////  Swizzling.swift
////  JoTravel
////
////  Created by tong on 15/11/30.
////  Copyright © 2015年 zhuxietong. All rights reserved.
////
//
//import Foundation
//import UIKit
//import Eelay
//import RTRootNavigationController
//
//
//
//
//
//
//@objc class RootCtr:NSObject {
//    
//    struct Static {
//        static var instance:RootCtr? = nil
//        static var token:Int = 0
//    }
//    
//    class func sharedInstance() -> RootCtr {
//        if Static.instance == nil
//        {
//            Static.instance = RootCtr()
//        }
//        return Static.instance!
//    }
//        
//    var controller : UIViewController?
//    var nav : UINavigationController?
//    required override init() {
//        super.init()
//    }
//}
//
public var __controller = UIViewController()
public var __nav:UINavigationController = UINavigationController()
//
//
//class Root:NSObject
//{
//    weak var currentNavCtr:UINavigationController?
//}
//
//extension DispatchQueue {
//    
//    private static var _onceTracker = [String]()
//    
//    class func do_once(token: String, block:()->Void) {
//        objc_sync_enter(self); defer { objc_sync_exit(self) }
//        
//        if _onceTracker.contains(token) {
//            return
//        }
//        _onceTracker.append(token)
//        block()
//    }
//}
//
//
//private struct __controller__swizzing {
//    static var valid = "__controller__swizzing_valid"
//}
//extension UIViewController
//{
//    public var __valid__controller:Bool{
//        get{
//            if let obj = objc_getAssociatedObject(self, &__controller__swizzing.valid) as? String
//            {
//                return (obj == FK.YES)
//            }
//            let newValue = FK.YES
//                        objc_setAssociatedObject(self, &__controller__swizzing.valid, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
//            return true
//        }
//        set{
//            let value = newValue ? FK.YES : FK.NO
//            objc_setAssociatedObject(self, &__controller__swizzing.valid, value, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
//            
//        }
//    }
//}
//
//
//
//extension UIViewController {
//    public static var globalViewDidLoad:(UIViewController)->Void = {
//        _ in
//    }
//    
//    public func isInClasses(names:[String])->Bool{
//        let desc = self.description
//        for name in names {
//            if desc.contains(name){
//                return true
//            }
//        }
//        return false
//    }
//  
//     public static var current:UIViewController{
//        return __controller
//    }
//    public static var hidenNavClasses:[String] = []//考虑接阿里SDK,RTNavigationController 时部分控制器需要隐藏navigationBar
//    
//    
//    public static func __swizzing() {
//        struct Static {
//            static var token: Int = 0
//        }
//        
//        if self !== UIViewController.self {
//            return
//        }
//        
//        DispatchQueue.do_once(token: "UIViewController_init") {
//            
//            let originalSelector3 = #selector(UIViewController.viewWillDisappear(_:))
//            let swizzledSelector3 = #selector(UIViewController.me_viewWillDisappear(_:))
//            
//            let originalMethod3 = class_getInstanceMethod(self, originalSelector3)
//            let swizzledMethod3 = class_getInstanceMethod(self, swizzledSelector3)
//            
//            let didAddMethod3 = class_addMethod(self, originalSelector3, method_getImplementation(swizzledMethod3!), method_getTypeEncoding(swizzledMethod3!))
//            
//            if didAddMethod3 {
//                class_replaceMethod(self, swizzledSelector3, method_getImplementation(originalMethod3!), method_getTypeEncoding(originalMethod3!))
//            } else {
//                method_exchangeImplementations(originalMethod3!, swizzledMethod3!);
//            }
//
//            
//            let originalSelector1 = #selector(UIViewController.viewDidLoad)
//            let swizzledSelector1 = #selector(UIViewController.me_viewDidLoad)
//            
//            let originalMethod1 = class_getInstanceMethod(self, originalSelector1)
//            let swizzledMethod1 = class_getInstanceMethod(self, swizzledSelector1)
//            
//            let didAddMethod1 = class_addMethod(self, originalSelector1, method_getImplementation(swizzledMethod1!), method_getTypeEncoding(swizzledMethod1!))
//            
//            if didAddMethod1 {
//                class_replaceMethod(self, swizzledSelector1, method_getImplementation(originalMethod1!), method_getTypeEncoding(originalMethod1!))
//            } else {
//                method_exchangeImplementations(originalMethod1!, swizzledMethod1!);
//            }
//            
//            let originalSelector = #selector(UIViewController.viewWillAppear(_:))
//            let swizzledSelector = #selector(UIViewController.me_viewWillAppear(_:))
//            
//            let originalMethod = class_getInstanceMethod(self, originalSelector)
//            let swizzledMethod = class_getInstanceMethod(self, swizzledSelector)
//            
//            let didAddMethod = class_addMethod(self, originalSelector, method_getImplementation(swizzledMethod!), method_getTypeEncoding(swizzledMethod!))
//            
//            if didAddMethod {
//                class_replaceMethod(self, swizzledSelector, method_getImplementation(originalMethod!), method_getTypeEncoding(originalMethod!))
//            } else {
//                method_exchangeImplementations(originalMethod!, swizzledMethod!);
//            }
//
//            
//            let originalSelector2 = #selector(UIViewController.viewDidAppear(_:))
//            let swizzledSelector2 = #selector(UIViewController.me_viewDidAppear(_:))
//            
//            let originalMethod2 = class_getInstanceMethod(self, originalSelector2)
//            let swizzledMethod2 = class_getInstanceMethod(self, swizzledSelector2)
//            
//            let didAddMethod2 = class_addMethod(self, originalSelector2, method_getImplementation(swizzledMethod2!), method_getTypeEncoding(swizzledMethod2!))
//            
//            if didAddMethod2 {
//                class_replaceMethod(self, swizzledSelector2, method_getImplementation(originalMethod2!), method_getTypeEncoding(originalMethod2!))
//            } else {
//                method_exchangeImplementations(originalMethod2!, swizzledMethod2!);
//            }
//
//            let originalSelector4 = #selector(UIViewController.viewWillLayoutSubviews)
//            let swizzledSelector4 = #selector(UIViewController.me_viewWillLayoutSubviews)
//            
//            let originalMethod4 = class_getInstanceMethod(self, originalSelector4)
//            let swizzledMethod4 = class_getInstanceMethod(self, swizzledSelector4)
//            
//            let didAddMethod4 = class_addMethod(self, originalSelector4, method_getImplementation(swizzledMethod4!), method_getTypeEncoding(swizzledMethod4!))
//            
//            if didAddMethod4 {
//                class_replaceMethod(self, swizzledSelector4, method_getImplementation(originalMethod4!), method_getTypeEncoding(originalMethod4!))
//            } else {
//                method_exchangeImplementations(originalMethod4!, swizzledMethod4!);
//            }
//
//            
//        }
//    }
//    
//    
//    var validPresent:Bool{
//        var valid = true
//
//        let obj_str = "\(self)"
//
//        if !self.__valid__controller{
//            valid = false
//        }
//        let strs = [
//            "UIInput",
//            "InputView",
//            "UIAlertController",
//            "UIApplicationRotationFollowingController",
//            "PopupDialog",
//            "RTContainerController",
//            "RTContainerNavigationController"
//        ]
//        if obj_str.contain(strings: strs)
//        {
//            valid = false
//        }
//
//        return valid
//
//    }
//    
//    @objc func me_viewWillLayoutSubviews()
//    {
//        self.me_viewWillLayoutSubviews()
//        switch EeTopStyle.mode{
//        case .rtnav:
//            break
//        default:
//            bringEeNavbar()
//        }
//    }
//    
//        
//    @objc func me_viewDidLoad() {
//        
//        _didLoad()
//        self.me_viewDidLoad()
//        __didLoad()
//        view._mo_owner_controller = self//和mo.controller 属性有关
//        
//        let back = UIBarButtonItem(title: "   ", style: .plain, target: nil, action: nil)
//        back.setBackButtonTitlePositionAdjustment(UIOffset(horizontal: 0, vertical: -60), for: .default)
////        let back = UIBarButtonItem(image: AppTheme.nav_back_img, style: .plain, target: nil, action: nil)
//        
//        self.navigationItem.backBarButtonItem = back
//        
//      UIViewController.globalViewDidLoad(self)
//
//        
////        self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "返回", style: .plain, target: nil, action: nil)
//        
//
//    }
//    
//    
//    @objc func me_viewDidAppear(_ animated: Bool) {
//        _didAppear(animated)
//        self.me_viewDidAppear(animated)
//        __didAppear(animated)
//        if validPresent
//        {
//            __controller = self
//        }
//        _ = TP.bottomLayoutGuide
//    }
//    
//    @objc func me_viewWillDisappear(_ animated: Bool) {
//        _willDisappear(animated)
//        self.me_viewWillDisappear(animated)
//        __willDisappear(animated)
//    }
//    
//    
//    @objc func me_viewWillAppear(_ animated: Bool) {
//        _willAppear(animated)
//        self.me_viewWillAppear(animated)
////        print("-----OOOOiiiii||\(self)")
//        switch EeTopStyle.mode {
//        case .eenav:
//            self.top_style.playUp()
//        default:
//            break
//        }
//
//        __willAppear(animated)
//    
//        if validPresent
//        {
//            __controller = self
//        }
//    }
//}
//
//extension UIViewController{
//    open func _didLoad() {
//        
//    }
//    
//    open func __didLoad() {
//        
//    }
//    
//    open func _didAppear(_ animated: Bool){
//        
////        weak var wself = self
////        UIView.animate(withDuration: 0.1, delay: 0.1, options: UIViewAnimationOptions.curveEaseInOut, animations: {
////           wself?.sobar_init.alpha = 1
////        }, completion: { (finish) in
////           wself?.sobar_init.alpha = 1
////        })
//    }
//    
//    open func __didAppear(_ animated: Bool){
//
//        
//    }
//    
//    open func _willDisappear(_ animated: Bool)
//    {
//        
//    }
//    
//    open func __willDisappear(_ animated: Bool)
//    {
////        if CtrStyle.valid{
//////            self.hidenSoNavBar()
////        }
//    }
//    
//    
//    open func _willAppear(_ animated: Bool){
//
//    }
//    
//    open func __willAppear(_ animated: Bool){
////        if CtrStyle.valid{
////            self.showSoNavbar()
////        }
//    }
//}
//
